<?php
/* *
 * 功能：彩虹易支付异步通知页面
 */
require_once("../../includes/fun.global.php");
require_once("epay.config.php");
require_once("epay_notify.class.php");
global $alipay_config;
//计算得出通知验证结果
$alipayNotify = new AlipayNotify($alipay_config);
$verify_result = $alipayNotify->verifyNotify($_REQUEST);


if ($verify_result && ($conf['pay_qqapy'] <> -1 || $conf['pay_wxpay'] <> -1 || $conf['pay_alipay'] <> -1 || !empty($conf['pay_url']))) { //验证成功
    //商户订单号
    $out_trade_no = (int)$_QET['out_trade_no'];

    //支付宝交易号

    $trade_no = $_REQUEST['trade_no'];

    //交易状态
    $trade_status = $_REQUEST['trade_status'];

    //金额
    $money = (float)$_REQUEST['money'];

    $srow = $DB->get_row("SELECT * FROM sky_pay WHERE `order`='{$out_trade_no}' limit 1 ");

    if ($_REQUEST['trade_status'] == 'TRADE_SUCCESS' && $srow['state'] == 2 && $srow['money'] >= $money) {
        $acc = $DB->get_row("SELECT * FROM `sky_order` WHERE `order` = '$out_trade_no' ORDER BY `id` DESC LIMIT 1");
        if ($acc['order'] <> ''&&$acc) die('success');
        //付款完成后，支付系统发送该交易状态通知
        \pay::success($_REQUEST, 2);
    } else echo "success";
} else {
    //验证失败
    echo "fail";
}